home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / pcl4c60.zip / LOGIN.C < prev    next >
Text File  |  1996-10-20  |  5KB  |  202 lines

  1. /*
  2. **  login.c (3/3/95)
  3. **
  4. **  Logs onto MarshallSoft BBS as 'GUEST GUEST'
  5. */
  6.  
  7. #define RTS_CTS_CONTROL 1
  8.  
  9. /************************/
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <malloc.h>
  14. #include <dos.h>
  15. #include <string.h>
  16. #include <conio.h>
  17. #include "modem_io.h"
  18. #include "pcl4c.h"
  19.  
  20. #define FALSE 0
  21. #define TRUE !FALSE
  22. #define CTLZ 0x1a
  23.  
  24. /*** Global Variables ***/
  25.  
  26. int Port;                 /* COM Port */
  27. int CharPace = 3;         /* inter-char delay in tics */
  28. int BaudCode;             /* baud rate code ( index into BaudRate[] ) */
  29. char *BaudRate[10] =  {"300","600","1200","2400","4800","9600",
  30.                        "19200","38400","57600","115200"};
  31. char *ModelText[4] =  {"Small","Compact","Medium","Large"};
  32.  
  33. /*** local prototypes ***/
  34.  
  35. int BaudMatch(char *);
  36. int PutGet(char *,char *,int);
  37. void ErrorCheck(int);
  38. void MyExit(char *);
  39.  
  40. /*** main ***/
  41.  
  42. #define ONE_SEC 18
  43.  
  44. void main(int argc, char *argv[])
  45. {char c;
  46.  int  i, rc;
  47.  char far *Ptr;
  48.  int  Seg;
  49.  int  Code;
  50.  int  Version;
  51.  char Temp[80];
  52.  if(argc!=3)
  53.    {printf("Usage: LOGIN <port> <baud>\n");
  54.     exit(1);
  55.    }
  56.  /* get port number from command line */
  57.  Port = atoi(argv[1]) - 1;
  58.  if((Port<COM1) || (Port>COM20))
  59.    {printf("Port must be COM1 to COM20n");
  60.     exit(1);
  61.    }
  62.  /* get baud rate from command line */
  63.  BaudCode = BaudMatch(argv[2]);
  64.  if(BaudCode<0)
  65.    {printf("Cannot recognize baud rate = %s\n",argv[2]);
  66.     exit(1);
  67.    }
  68.  /* setup 512 byte receive buffer */
  69.  Ptr = (char far *) _fmalloc(512+16);
  70.  Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
  71.  SioRxBuf(Port,Seg,Size512);
  72.  /* setup 128 byte transmit buffer */
  73.  Ptr = (char far *) _fmalloc(128+16);
  74.  Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
  75.  SioTxBuf(Port,Seg,Size128);
  76.  /* set port parmameters */
  77.  ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
  78.  /* reset the port */
  79.  ErrorCheck( SioReset(Port,BaudCode) );
  80.  /* set DTR and RTS */
  81.  ErrorCheck( SioDTR(Port,'S') );
  82.  ErrorCheck( SioRTS(Port,'S') );
  83.  /* display some info */
  84.  printf(" -- LOGIN (3/5/95) --\n");
  85.  Version = SioInfo('V');
  86.  sprintf(Temp,"      Library: %d.%d\n",Version>>4,0x0f&Version);
  87.  printf(Temp);
  88.  sprintf(Temp," Memory Model: %s\n",ModelText[3&SioInfo('M')] );
  89.  printf(Temp);
  90.  strcpy(Temp,"TX Interrupts: ");
  91.  if(SioInfo('I')) strcat(Temp,"YES\n");
  92.  else strcat(Temp,"NO\n");
  93.  printf(Temp);
  94. #if RTS_CTS_CONTROL
  95.  SioFlow(Port,10*ONE_SEC);
  96.  printf(" Flow Control: YES\n");
  97. #else
  98.  printf(" Flow Control: NO\n");
  99. #endif
  100.  /* Set FIFO level */
  101.  printf("   16550 UART: ");
  102.  if( SioFIFO(Port,LEVEL_14) ) printf("YES\n");
  103.  else printf("NO\n");
  104.  /* clear PCL4C receive buffer */
  105.  ErrorCheck( SioRxClear(Port) );
  106.  printf("\n");
  107.  /* wait for Modem to say its ready */
  108.  printf("  <<Waiting for Modem DSR>>\n");
  109.  while( !SioDSR(Port) )
  110.    {if(kbhit()||SioBrkKey()) MyExit("Aborted by user");
  111.     printf(".");
  112.     SioDelay(ONE_SEC);
  113.    }
  114.  printf("  <<DSR on>>\n");
  115.  
  116. #if RTS_CTS_CONTROL
  117.  printf("  <<Waiting for Modem CTS>>\n");
  118.  while( !SioCTS(Port) )
  119.    {if(kbhit()||SioBrkKey()) MyExit("Aborted by user");
  120.     printf(".");
  121.     SioDelay(ONE_SEC);
  122.    }
  123.  printf("  <<CTS on>>\n");
  124. #endif
  125.  /* initialize (Hayes compatible) modem */
  126.  Code = PutGet("!AT!","OK",ONE_SEC);
  127.  if(Code) Code = PutGet("AT E1 S7=60 S11=60 V1 X1 Q0!","OK",5*ONE_SEC);
  128.  if(Code)
  129.    {printf("  <<Modem ready. Logging on...>>\n");
  130.     /* log onto MarshallSoft BBS as GUEST */
  131.     Code = PutGet("!ATDT880,9748!","CONNECT",60*ONE_SEC);
  132.     if(Code) Code = PutGet("!","graphics (y/N)?|LAST name:",45*ONE_SEC);
  133.     if(Code=='0') Code = PutGet("!","LAST name:",10*ONE_SEC);
  134.     if(Code) Code = PutGet("GUEST GUEST!","password:",10*ONE_SEC);
  135.     if(Code) Code = PutGet("GUEST!",NULL,10*ONE_SEC);
  136.    }
  137.  else printf("\n  <<WARNING: Expected OK not received>>\n");
  138.  /* user now has control */
  139.  printf("Enter terminal loop ( Type ^Z to exit )\n");
  140.  /* enter terminal loop */
  141.  while(TRUE)
  142.      {/* was key pressed ? */
  143.       if(kbhit())
  144.           {i = getch();
  145.            if((char)i==CTLZ)
  146.               {printf("\n*** Hanging up modem\n");
  147.                ModemHangup(Port);
  148.                /* restore COM port status & exit */
  149.                SioDone(Port);
  150.                exit(1);
  151.               }
  152.            else SioPutc(Port,(char)i);
  153.           } /* end if */
  154.       /* any incoming over serial port ? */
  155.       i = SioGetc(Port,0);
  156.       if(i>-1) putch((char)i);
  157.      } /* end while */
  158. } /* end main */
  159.  
  160. /*** check return code ***/
  161.  
  162. void ErrorCheck(int Code)
  163. {/* trap PCL error codes */
  164.  if(Code<0)
  165.      {SioError(Code);
  166.       SioDone(Port);
  167.       exit(1);
  168.      }
  169. } /* end ErrorCheck */
  170.  
  171. /*** find baud rate index ***/
  172.  
  173. int BaudMatch(char *P)
  174. {int i;
  175.  /* find baud rate in table */
  176.  for(i=0;i<10;i++) if(strcmp(BaudRate[i],P)==0) return(i);
  177.  return(-1);
  178. }
  179.  
  180. /*** send string & expect reply ***/
  181.  
  182. int PutGet(char *Send,char *Expect,int Tics)
  183. {int rc;
  184.  printf("\n*** Sending '%s' ",Send);
  185.  if(Expect) printf(" & awaiting '%s'",Expect);
  186.  printf("\n");
  187.  rc = ModemSendTo(Port, CharPace, Send);
  188.  if(Expect)
  189.    {rc = ModemWaitFor(Port,Tics,FALSE,Expect);
  190.     if(rc<=0) printf("\nERROR: '%s' sent but '%s' not received\n",Send,Expect);
  191.    }
  192.  return rc;
  193. }
  194.  
  195. /*** common exit ***/
  196.  
  197. void MyExit(char *S)
  198. {printf("%s\n",S);
  199.  SioDone(Port);
  200.  exit(0);
  201. }
  202.